package com.wie.staffhubpro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wie.staffhubpro.domain.dto.DeptDTO;
import com.wie.staffhubpro.domain.entity.Dept;
import com.wie.staffhubpro.service.DeptService;
import com.wie.staffhubpro.mapper.DeptMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
* @author WiedersehenM
* @description 针对表【dept】的数据库操作Service实现
* @createDate 2025-06-26 21:47:23
*/
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept>
    implements DeptService{

    @Autowired
    private DeptMapper deptMapper;

    /**
     * 新增部门
     * @param deptDTO
     */
    public void addDept(DeptDTO deptDTO) {
        Dept dept = new Dept();
        BeanUtils.copyProperties(deptDTO, dept);
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    /**
     * 根据id修改部门信息
     */
    public void alterDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateById(dept);
    }

    /**
     * 根据部门名称模糊查询部门
     */
    public List<Dept> getByName(String name) {
        QueryWrapper<Dept> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("dept_name", name);
        List<Dept> deptList = deptMapper.selectList(queryWrapper);
        return deptList;
    }
}




